package com.chen.test6;

public class PhoneTest {
    public static void main(String[] args) {


        // 创建一个数组
        Phone[] arr = new Phone[3];
        // 创建手机对象
        Phone p1 = new Phone("华为", 5000, "白色");
        Phone p2 = new Phone("小米", 5000, "白色");
        Phone p3 = new Phone("苹果", 5000, "白色");
        // 把手机对象添加到数组中
        arr[0] = p1;
        arr[1] = p2;
        arr[2] = p3;
        // 获取三部手机的平均价格
        int sum = 0;
        for (int i = 0; i < arr.length; i++) {
            // i表示索引  arr[i]表示元素
            Phone phone = arr[i];
            sum = sum + phone.getPrice();
        }
        // 求平均值
        int average = sum / arr.length;
        double avg = sum *1.0 / arr.length;
        System.out.println("平均价格：" + average);
        System.out.println("平均价格：" + avg);

    }
}
